if(condition) { if(condition) { statements ---------- } } next statements
import java.util.Scanner; class demo { public static void main(String args[]) { Scanner stdin=new Scanner(System.in); System.out.print("Enter a Number:"); int a=stdin.nextInt(); if(a>=10 && a<=99) { System.out.println("It is a 2 digit Number"); int x=a%10; int y=a/10; if(x==y) System.out.println("Both digits are same"); else System.out.println("Both digits are Not same"); } else System.out.println("It is not a 2 digit Number"); } }
Enter a Number: 22 It is a 2 digit Number Both digit are same
import java.util.Scanner; class demo { public static void main(String args[]) { Scanner stdin=new Scanner(System.in); System.out.print("Enter a Number:"); int a=stdin.nextInt(); if(a>0) { System.out.println("Number is Positive"); if(a%2==0) System.out.println("Even Number"); else System.out.println("Odd Number"); } else System.out.println("Number is Not Positive"); } }
Enter a Number: 22 Number is Positive Even Number
import java.util.Scanner; class demo { public static void main(String args[]) { Scanner stdin=new Scanner(System.in); System.out.print("Enter 3 Angles:"); int a=stdin.nextInt(); int b=stdin.nextInt(); int c=stdin.nextInt(); if(a+b+c==180) { System.out.println("Triangle can be formed"); if(a==b && b==c) System.out.println("Eq.Triangle"); if(a==b || b==c || c==a) System.out.println("Iso.Triangle"); if(a==90 || b==90 || c==90) System.out.println("Rt.Ag.Triangle"); } else System.out.println("Triangle cannot be formed"); } }
Enter a Angles 45 90 45 Triangle can be formed Iso. Triangle